package com.app.library.utils;

/**
 * create by colin 2019/4/22
 */
public class FastClickUtils {

    private static final int MIN_DELAY_TIME = 500;  // 两次点击间隔不能少于500ms
    private static long lastClickTime = 0L;

    public static boolean isFastClick() {
        long currentClickTime = System.currentTimeMillis();
        if (Math.abs(currentClickTime - lastClickTime) >= MIN_DELAY_TIME) {
            lastClickTime = currentClickTime;
            return false;
        }
        return true;
    }

    private static boolean isFastClick(int time) {
        long currentClickTime = System.currentTimeMillis();
        if (Math.abs(currentClickTime - lastClickTime) >= time) {
            lastClickTime = currentClickTime;
            return false;
        }
        return true;
    }

    public static boolean safeClick() {
        return !isFastClick();
    }

    /**
     * 支持自定义间隔
     *
     * @param time 间隔时间 单位 毫秒
     */
    public static boolean safeClick(int time) {
        return !isFastClick(time);
    }

}
